package com.nineclock.attendance.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nineclock.attendance.dto.OvertimeRuleDTO;
import com.nineclock.attendance.mapper.OvertimeRuleMapper;
import com.nineclock.attendance.pojo.OvertimeRule;
import com.nineclock.attendance.service.OvertimeRuleService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.utils.BeanHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
@Transactional
public class OvertimeRuleServiceImpl implements OvertimeRuleService {

    @Autowired
    private OvertimeRuleMapper ruleMapper;

    @Override
    public PageResult<OvertimeRuleDTO> qureyOvertimePage(Integer page, Integer pageSize) {


        IPage<OvertimeRule> ipage=new Page<>(page,pageSize);
        ipage= ruleMapper.selectPage(ipage,null);
        List<OvertimeRule> records = ipage.getRecords();

        if (!CollectionUtils.isEmpty(records)){

            List<OvertimeRuleDTO> overtimeRuleDTOS = BeanHelper.copyWithCollection(records, OvertimeRuleDTO.class);

            return new PageResult<>(ipage.getTotal(),ipage.getPages(),overtimeRuleDTOS);
        }

        return null;
    }
}
